package com.admission.web.admin;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.Log;
import com.admission.service.LogManager;
import com.admission.util.PageUtils;
import com.admission.web.CrudActionSupport;

@Namespace("/admin")
public class LogAdminAction extends CrudActionSupport<Log> {

	private static final long serialVersionUID = -6425007031597284541L;
	private String id;
	private Log entity;
	private Page<Log> page = new Page<Log>(PageUtils.DEFAULT_PAGE_SIZE);
	private LogManager logManager;
	private String ids;

	public Log getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		page.setOrder(Page.DESC);
		page.setOrderBy("inputTime");
		logManager.getAll(page);
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return list();
	}

	@Override
	public String save() throws Exception {
		return list();
	}

	@Override
	public String delete() throws Exception {
		logManager.delete(ids);
		Struts2Utils.renderText("true");
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (StringUtils.isEmpty(id)) {
			entity = new Log();
		} else {
			entity = logManager.getById(id);
		}

	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Log getEntity() {
		return entity;
	}

	public void setEntity(Log entity) {
		this.entity = entity;
	}

	public Page<Log> getPage() {
		return page;
	}

	public void setPage(Page<Log> page) {
		this.page = page;
	}

	@Autowired
	public void setLogManager(LogManager logManager) {
		this.logManager = logManager;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

}
